import jssdk from './lib'
const {
	deepMerge,
	config
} = jssdk
class Main {
	static getInstance() {
		if (!this.instance) {
			this.instance = new Main();
		}
		return this.instance;
	}
	constructor(arg) {
		this.instance = null
		this.$uni = {}
		this.$config = {}
	}
	config(res) {
		this.$config = jssdk.config = deepMerge(config, res)
		this.$uni = jssdk
	}
	install(Vue) {
		const data = this.$config
		Vue.prototype[data.root] = this.$uni
		uni[data.root] = this.$uni
		let event = Promise.resolve((r) => setTimeout(r))
		let logStyle =
			'border: 1px #000 solid;padding: 2px 5px;border-radius: 5px;background-color: #333;color: #F0AD4E;'
		event.then((r) => r(console.log.bind(console, `%c- 项目日志${this.$config.silent?'开启':'关闭'} -`, logStyle)))
	}
}

const main = Main.getInstance()
export default {
	config: main.config,
	install: main.install
}
